package com.eyas.core.jdbc.utils;

import org.springframework.jdbc.core.SqlParameterValue;
import org.springframework.jdbc.core.SqlTypeValue;
import org.springframework.jdbc.core.StatementCreatorUtils;
import org.springframework.jdbc.core.support.AbstractInterruptibleBatchPreparedStatementSetter;
import org.springframework.lang.Nullable;

import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.List;

/**
 * @Auther: 王龙龙
 * @Date: 2019/3/30 10:32
 * @Description:
 */
public class JdbcBatchPreparedStatementSetter extends AbstractInterruptibleBatchPreparedStatementSetter {

    private int batchSize = Integer.MAX_VALUE;
    private List<Object[]> updateArgList; //需要处理的参数

    public JdbcBatchPreparedStatementSetter(List<Object[]> updateArgs) {
        if(updateArgs!=null&&updateArgs.size()>0) {
            this.batchSize = updateArgs.size();
            this.updateArgList = updateArgs;
        }
    }

    @Override
    public boolean setValuesIfAvailable(PreparedStatement ps, int i) throws SQLException {
        if(updateArgList==null||updateArgList.size()==0)
            return false;
        Object[] updateArgs = updateArgList.get(i);
        JdbcPrepareParam.setStatementParameters(updateArgs,ps);
        if(i==updateArgList.size()-1)
            return false;
        return true;
    }


}
